package com.googlecode.agscrum.model.exceptions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@SuppressWarnings("serial")
public class GScrumDomainException extends RuntimeException {
	public enum TypeMessage {
		INFO, ERROR, WARNING, FATAL
	}

	private Throwable parent;

	private List<GScrumMessageException> messages = new ArrayList<GScrumMessageException>();

	public GScrumDomainException(GScrumMessageException gScrumMessageException) {
		addMessage(gScrumMessageException);
	}

	public GScrumDomainException(GScrumMessageException gScrumMessageException,
			Throwable parent) {
		addMessage(gScrumMessageException);
		this.parent = parent;
	}

	public GScrumDomainException(Throwable parent) {
		this(
				new GScrumMessageException("msg.default.error",
						TypeMessage.ERROR), parent);
	}

	public void addMessage(GScrumMessageException gScrumMessageException) {
		if (messages == null) {
			messages = new ArrayList<GScrumMessageException>();
		}
		messages.add(gScrumMessageException);
	}

	public GScrumDomainException() {

	}

	public void setParent(Throwable parent) {
		this.parent = parent;
	}

	public Throwable getParent() {
		return parent;
	}

	public List<GScrumMessageException> getMessages() {
		return Collections.unmodifiableList(messages);
	}

}
